import {doNothing, eFrameMode, eRenderMode, iMicroApp, iMicroIndexConfig, iMicroMainConfig} from "@peryl/micro-web";
import {MicroAppModule} from "./MicroAppModule";

const defaultPublicPathGetter = () => '';

export const microAppCreateLocalIndexConfig = MicroAppModule.createRegistration((microApp) => {
  const createLocalIndexConfig: iMicroApp['createLocalIndexConfig'] = (data) => {
    return {
      frameMode: eFrameMode.none,
      renderMode: eRenderMode.base,
      indexConfigDetail: () => {
        const indexConfig: iMicroIndexConfig = {
          getPublicPath: defaultPublicPathGetter, setPublicPath: doNothing, base: defaultPublicPathGetter, onBeforeLoadMain: doNothing, onStartBySelf: doNothing,
          main: () => {
            const mainConfig: iMicroMainConfig = {
              getPublicPath: defaultPublicPathGetter, setPublicPath: doNothing,
              frameMode: { base: { getPageComponent: data.getPageComponent } }
            };
            return mainConfig;
          },
        };
        return indexConfig;
      },
    };
  };
  return createLocalIndexConfig;
});
